import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/index.vue'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/dashboard',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Dashboard',
        component: () => import('@/views/Dashboard.vue'),
        meta: { title: '首页', icon: 'House' }
      }
    ]
  },
  {
    path: '/channel',
    component: Layout,
    meta: { title: '渠道管理', icon: 'Connection' },
    children: [
      {
        path: 'upstream',
        name: 'Upstream',
        component: () => import('@/views/channel/Upstream.vue'),
        meta: { title: '上游渠道', icon: 'Connection' }
      },
      {
        path: 'downstream',
        name: 'Downstream',
        component: () => import('@/views/channel/Downstream.vue'),
        meta: { title: '下游渠道', icon: 'Connection' }
      }
    ]
  },
  {
    path: '/distribution',
    component: Layout,
    meta: { title: '分发方案', icon: 'Share' },
    children: [
      {
        path: 'scheme',
        name: 'DistributionScheme',
        component: () => import('@/views/distribution/Scheme.vue'),
        meta: { title: '方案配置', icon: 'Share' }
      }
    ]
  },
  {
    path: '/engine',
    component: Layout,
    meta: { title: '数据处理', icon: 'DataLine' },
    children: [
      {
        path: 'config',
        name: 'EngineConfig',
        component: () => import('@/views/engine/Config.vue'),
        meta: { title: '数据处理引擎', icon: 'DataLine' }
      },
      {
        path: 'field-mapping',
        name: 'FieldMapping',
        component: () => import('@/views/engine/FieldMapping.vue'),
        meta: { title: '字段映射', icon: 'DataLine' }
      },
      {
        path: 'validation-rules',
        name: 'ValidationRules',
        component: () => import('@/views/engine/ValidationRules.vue'),
        meta: { title: '验证规则', icon: 'DataLine' }
      },
      {
        path: 'script-config',
        name: 'ScriptConfig',
        component: () => import('@/views/engine/ScriptConfig.vue'),
        meta: { title: '脚本配置', icon: 'DataLine' }
      },
      {
        path: 'collision-check',
        name: 'CollisionCheck',
        component: () => import('@/views/engine/CollisionCheck.vue'),
        meta: { title: '碰撞检测', icon: 'DataLine' }
      }
    ]
  },
  {
    path: '/monitor',
    component: Layout,
    meta: { title: '数据监控', icon: 'Monitor' },
    children: [
      {
        path: 'realtime',
        name: 'MonitorRealtime',
        component: () => import('@/views/monitor/index.vue'),
        meta: { title: '实时监控', icon: 'Monitor' }
      }
    ]
  },
  {
    path: '/crm',
    component: Layout,
    meta: { title: 'CRM管理', icon: 'UserFilled' },
    children: [
      {
        path: 'customer',
        name: 'CustomerManagement',
        component: () => import('@/views/crm/CustomerManagement.vue'),
        meta: { title: '客户信息', icon: 'UserFilled' }
      },
      {
        path: 'follow',
        name: 'FollowUpManagement',
        component: () => import('@/views/crm/FollowUpManagement.vue'),
        meta: { title: '跟进记录', icon: 'UserFilled' }
      },
      {
        path: 'allocation',
        name: 'AllocationManagement',
        component: () => import('@/views/crm/AllocationManagement.vue'),
        meta: { title: '分配记录', icon: 'UserFilled' }
      },
      {
        path: 'customer/detail/:id',
        name: 'CustomerDetail',
        component: () => import('@/views/crm/CustomerDetail.vue'),
        meta: { title: '客户详情', icon: 'UserFilled' },
        hidden: true
      },
      {
        path: 'transfer',
        name: 'CustomerTransfer',
        component: () => import('@/views/crm/CustomerTransfer.vue'),
        meta: { title: '客户转移', icon: 'UserFilled' }
      },
      {
        path: 'analytics',
        name: 'FollowUpAnalytics',
        component: () => import('@/views/crm/FollowUpAnalytics.vue'),
        meta: { title: '跟进分析', icon: 'UserFilled' }
      },
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理', icon: 'Setting' },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/User.vue'),
        meta: { title: '用户管理', icon: 'User' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/Role.vue'),
        meta: { title: '角色管理', icon: 'Avatar' }
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/system/Menu.vue'),
        meta: { title: '菜单管理', icon: 'Menu' }
      },
      {
        path: 'tenant',
        name: 'Tenant',
        component: () => import('@/views/system/Tenant.vue'),
        meta: { title: '租户管理', icon: 'OfficeBuilding' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router